<?php
class FilterController extends BaseController
{
    public function __construct($uri)
    {
        parent::__construct($uri);
    }

    public function getMovies()
    {
        $tmp = explode('/', $this->uri);
        $this->output['data']['filter']['level1'] = $tmp[1]; //为什么叫level1第一级，因为前面是 免费、收费，后面是 分数，没有一个合适的名字。
        if(is_numeric($tmp[1])) {
            $where = array(
                'e' => array(
                    'is_direct_download' => 1,
                ),
                'gte' => array(
                    'rating' => $tmp[1],
                ),
                'lt' => array(
                    'rating' => $tmp[1] + 1, //7-7.9没问题，但9-9.9导致10分的怎么办？todo
                ),
            );
            $this->output['data']['html_title'] = '豆瓣下电影 ' . $tmp[1] . '分';
        } else {
            switch($tmp[1]) {
            case '0-6' :
                $where = array(
                    'e' => array(
                        'is_direct_download' => 1,
                    ),
                    'lte' => array(
                        'rating' => 6.9,
                    ),
                );
                $this->output['data']['html_title'] = '豆瓣下电影 0-6.9分';
                break;
            case 'free_genuine_download' :
                $where = array(
                    'e' => array(
                        'is_free' => 1,
                        'is_genuine' => 1,
                    ),
                );
                $this->output['data']['html_title'] = '豆瓣下电影 免费正版下载';
                break;
            case 'buy_genuine_download' :
                $where = array(
                    'e' => array(
                        'is_free' => 0,
                        'is_genuine' => 1,
                    ),
                );
                $this->output['data']['html_title'] = '豆瓣下电影 收费正版下载';
                break;
            }
        }
        $m = new MovieModel();
        $movies = $m->getLastestMovies($where, 0, 100);
        $this->output['http']['cache-control'] = array(
            'public',
            'max-age' => 60, //todo 为什么定60
        );
        $this->output['data']['movies'] = $movies;
        $this->output['tpl'] = 'filter';
        return $this->output;
    }
}
?>
